#include <iostream>
#include <string>
using namespace std;


int main(){
	int t;
	cin>>t;
	for(int h=0;h<t;h++){
		string s,ans="";
		int k;
		cin>>s>>k;
		int sum=k;
		int index=0;
		for(int i=0;i<s.length()-k;i++){
			if(sum == 0){
				for(int i=index;i<s.length())
			}
			int smin=0x7fffffff,anssum;
			for(int j=0;j<=sum;j++){
				if(smin > s[index+j]){
					anssum = j;
					smin = s[index+j];
				}
			}
			if(ans.length() != 0  ||  smin != '0')
				ans += (char)smin;
			sum -= anssum;
			index += anssum+1;
		}
		if(ans.length() == 0)
			cout<<0<<endl;
		else
			cout<<ans<<endl;
	}
	return 0;
}
